package com.ncloud.crm.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;

/**
 * Created by shiqiang on 2017/4/11.
 * @describe: 简单工作流工具类，负责真实调用BS_P_DELEGATION中配置的函数
 */
public class WorkFlowUtil {

    /*按照顺序执行调用服务*/
    public static void executeFunctions(List<Map<String,String>> list, JSONObject json) throws NoSuchMethodException, SecurityException, ClassNotFoundException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
        for(Map<String,String> map : list){
            String className = map.get("CLASSNAME");
            String classAndMethod = map.get("CONFIGURATION");
            if(className.equals("Class")){
                String classz = classAndMethod.split("-")[0];
                Method method = Class.forName(classz).getMethod(classAndMethod.split("-")[1], JSONObject.class);
                Object obj = Utility.getBean(classz);
//				sataMap = (SataMap) method.invoke(obj, sataMap);
                Object result = method.invoke(obj, json);
                if(result instanceof JSONObject) json = (JSONObject)result;
            }
        }
    }
}
